#
#
#
#
#
#
#



from CvPythonExtensions import *

import Popup as PyPopup
import CvUtil
import sys

import JZoCUtils

############################

# globals
gc = CyGlobalContext()


############################################################################






##############################################################
# These are basic 'get' methods. They return various values. #
##############################################################

# This method starts with the number 0
# It then iterates through the 8 tiles surrounding pPlot and for
# each tile that is the center of a ZoC 1 is added to the number
# It then returns the intager number (on all failures a 0 is returned)
# Note pPlot itself is not checked or counted in any way
def getFortZoCCount(pPlot):

        # Return immediately if the plot passed in is invalid
	if (pPlot == None):
		return 0
			
	# Return immediately if the plot passed in is invalid
	if (pPlot.isNone()):
		return 0

        iX = pPlot.getX()
	iY = pPlot.getY()

	iFortZoCCounter = 0

	for iiX in range(iX-1, iX+2, 1):
                for iiY in range(iY-1, iY+2, 1):
                        pPlot = CyMap().plot(iiX,iiY)
                        if (JZoCUtils.isPlotZoC(pPlot)):
                                if (pPlot.getImprovementType() == gc.getInfoTypeForString("IMPROVEMENT_FORT")):
                                        iFortZoCCounter = iFortZoCCounter + 1

        return iFortZoCCounter



def getEnemyFortZoCCount(pPlot, iPlayer):

        pPlayer = gc.getPlayer(iPlayer)

	# Return immediately if the player passed in is invalid
	if (pPlayer == None):
		return False
			
	# Return immediately if the player passed in is invalid
	if (pPlayer.isNone()):
		return False

        eTeam = pPlayer.getTeam()

        # Return immediately if the plot passed in is invalid
	if (pPlot == None):
		return 0
			
	# Return immediately if the plot passed in is invalid
	if (pPlot.isNone()):
		return 0

        iX = pPlot.getX()
	iY = pPlot.getY()

	iEnemyFortZoCCounter = 0

	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pPlot = CyMap().plot(iiX,iiY)
			if (JZoCUtils.isPlotEnemyZoC(pPlot, iPlayer)):
                                if (pPlot.getImprovementType() == gc.getInfoTypeForString("IMPROVEMENT_FORT")):
                                        iEnemyFortZoCCounter = iEnemyFortZoCCounter + 1

        return iEnemyFortZoCCounter
















